#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define BUFFER_SIZE  32

int main()
{   
    #if 0
    /*字符数组: 存放的是栈空间*/ //数组名就是首地址
    char buffer[BUFFER_SIZE] = "hello world";
    int size = sizeof(buffer);
    int len = strlen(buffer);
    printf("size = %d,\tlen:%d\n", size, len);

    strcpy(buffer,"257jiayou");
    printf("buffer:%s\n", buffer);
    

    /*字符串又被称为字符串常量，地址在全局区*/
       char *ptr = "hello world";
       int size = sizeof(ptr);
       int len = strlen(ptr);
       printf("size = %d,\tlen:%d\n", size, len);
       printf("%p\t%p\n", ptr, "hello world");

       strcpy(ptr, "257jiayou");
       printf("ptr:%s\n", ptr);
    #else
    char *ptr = (char *)malloc(sizeof(char)*BUFFER_SIZE);

    /*判空*/
    if(ptr == NULL)
    {
        perror("malloc error");
        exit(-1);

    }
    /*清楚脏数据*/
    memset(ptr, 0, sizeof(char)*BUFFER_SIZE);

    /*字符串拷贝*/
    strcpy(ptr, "257jiayou");
    printf("ptr:%s\n", ptr);

    /*释放堆空间*/
    free(ptr);

    #endif

    return 0;

}